// alert.js - 新建文件
class Alert {
    static show(message, type = 'info', duration = 3000) {
        const container = document.getElementById('alertContainer');
        const alert = document.createElement('div');
        alert.className = `alert ${type}`;
        alert.innerHTML = `
            <span class="alert-icon">${this.getIcon(type)}</span>
            ${message}
        `;

        container.appendChild(alert);
        setTimeout(() => alert.remove(), duration);
    }

    static confirm(message, title = '提示', type = 'info') {
        return new Promise((resolve) => {
            const modal = document.createElement('div');
            modal.className = 'alert-confirm';
            modal.innerHTML = `
                <div class="confirm-box">
                    <h4>${title}</h4>
                    <p>${message}</p>
                    <div class="confirm-actions">
                        <button class="cancel-btn">取消</button>
                        <button class="confirm-btn">确定</button>
                    </div>
                </div>
            `;

            document.body.appendChild(modal);

            modal.querySelector('.cancel-btn').addEventListener('click', () => {
                modal.remove();
                resolve(false);
            });

            modal.querySelector('.confirm-btn').addEventListener('click', () => {
                modal.remove();
                resolve(true);
            });
        });
    }

    static getIcon(type) {
        const icons = {
            success: '✓',
            error: '⚠',
            warning: '!',
            info: 'i'
        };
        return icons[type] || '';
    }
}

// 在需要替换alert的地方调用：
// Alert.show('操作成功', 'success');
// Alert.show('密码错误', 'error');